package map;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

public class MapDemo1 {
    public static void main(String[] args) {
        Map<String,Integer> map = new HashMap<>();
        map.put("语文",90);
        map.put("数学",80);
        Integer value = map.put("政治",70);
        System.out.println(value);
        map.put("化学",89);
        map.put("物理",78);
        System.out.println(map);
        value = map.put("物理",66);
        System.out.println(value);
        System.out.println(map);

        System.out.println(map.get("数学"));
        System.out.println(map.isEmpty());
        System.out.println(map.remove("语文"));
        System.out.println(map.size());
        System.out.println(map);
        Set<String> set = map.keySet();
        for (String k:set){
            System.out.println(k);
        }
        set.forEach(System.out::println);
        set.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        Collection<Integer> c = map.values();
        c.forEach(System.out::println);
        for (Integer v:c){
            System.out.println(v);
        }

        Set<Map.Entry<String,Integer>> entrySet = map.entrySet();
        entrySet.forEach(System.out::println);
        for (Map.Entry<String,Integer> entry:entrySet){
            String key = entry.getKey();
            Integer v = entry.getValue();
            System.out.println("key:"+key+"value:"+v);
        }
        map.forEach((k,v)-> System.out.println("key:"+k+"value:"+v));
    }
}
